// $Id: session.h 100 2011-10-21 15:05:36Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef SESSION_H_
#define SESSION_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <sys/tree.h>
#include <event.h>

#include <niohttp/server.h>

#include "stream.h"

struct niohttp_server;

struct zcbuffer;

struct niohttp_session {
	struct sockaddr_in remote;
	int fd;
	struct niohttp_session_item item;
	struct niohttp_request_decoder *decoder;
	struct zcbuffer *input_buffer;
	struct zcbuffer *output_buffer;
	struct zcbuffer *request_buffer;
	struct niohttp_server *server;
	int need_close;
	struct event read;
	struct event write;
	struct timeval timeout;
	struct event timer;
	struct timeval duration;
	struct niohttp_stream_list streams;
	RB_ENTRY(niohttp_session) entry;
};

struct niohttp_request;

int niohttp_session_reply(struct niohttp_session *session,
		struct niohttp_request *req, int code);

struct niohttp_track;

int niohttp_session_setup(struct niohttp_session *session,
		struct niohttp_track *track,
		struct niohttp_transport *transport);

void niohttp_session_track_cb(struct timeval *timestamp,
		struct zcbuffer *buffer, void *cbarg);

int niohttp_session_start(struct niohttp_session *session,
		struct sockaddr_in *remote);

int niohttp_session_pause(struct niohttp_session *session);

int niohttp_session_play(struct niohttp_session *session);

int niohttp_session_close(struct niohttp_session *session);

#ifdef __cplusplus
}
#endif

#endif /* SESSION_H_ */
